package com.util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * Created by 苏犇 on 2019/1/1. <br>
 */
public class MybatisUtil {
    private static MybatisUtil ourInstance = new MybatisUtil();

    public static MybatisUtil getInstance() {
        return ourInstance;
    }

    private InputStream in;

    private MybatisUtil() {
    }

    private void init(){
        in = Thread.currentThread().getContextClassLoader().getResourceAsStream("mybatis-config.xml");
    }

    public SqlSession getSqlSession(){
        this.init();
        SqlSessionFactory sf = new SqlSessionFactoryBuilder().build(in);
        return sf.openSession();
    }
}
